//
//  YGBodyHistoryViewController.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/28.
//

#import "YGBodyHistoryViewController.h"
#import "YGFormTableView.h"
#import "YGBodyDataBLL.h"
#import "YGBodyHistoryTableViewCell.h"
@interface YGBodyHistoryViewController ()
@property (nonatomic, strong) YGFormTableView  *formView;
@property (nonatomic, strong) NSMutableArray  *dataArray;

@end

@implementation YGBodyHistoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"自测历史记录";
    [self initView];
    [self initMas];
    [self requestData];
    // Do any additional setup after loading the view.
}

- (void)initView{
    [self.view addSubview:self.formView];
}

- (void)initMas{
    [self.formView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(20);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.bottom.mas_equalTo(20);
    }];
}

- (void)requestData{
    WeakSelf(self);
    [YGBodyDataBLL requestServerHistorySuccess:^(NSArray<YGBodyHistoryModel *> * _Nonnull model) {
        [weakself.dataArray addObjectsFromArray:model];
        [weakself.formView configureData:weakself.dataArray];
    } fail:^(NSError * _Nonnull error) {
        
    }];
}
- (YGFormTableView *)formView{
    if (!_formView) {
        YGFromTableConfigure *confi = [[YGFromTableConfigure alloc] init];
        confi.row = 4;
        YGFromHeaderConfigure *headerConfi = [[YGFromHeaderConfigure alloc] init];
        confi.cellHieght = 35;
        headerConfi.row = 4;
        confi.headerConfigure = headerConfi;
        _formView = [[YGFormTableView alloc] initWithConfigure:confi registerCell:YGBodyHistoryTableViewCell.class];
    }
    return _formView;
}

- (NSMutableArray *)dataArray{
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
        [_dataArray addObject:[self getTitles]];
    }
    return _dataArray;
}
- (NSArray *)getTitles{
    return @[@"体重",@"基础代谢率",@"BIMI指数",@"自测日期"];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
